package GUI;

import java.awt.*;
import java.io.IOException;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import logic.ClientModel;

public class ClientFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	final static String DEFALT_HOST = "localhost";
	final public static int DEFAULT_PORT = 5555;
	
	private ClientModel client;
	private JPanel contentPane;
	private TopBar topBar;
	private SideBar sideBar;
	private JPanel panel;
	
	public ClientFrame(){
		super();
	}
	
	public void init(){
		
		this.setSize(1000, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		contentPane.setBackground(Color.WHITE);
		this.setContentPane(contentPane);
		setTitle("Mat - Client");
		setResizable(false);
		setLocation(new Point(200, 100));
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		initTopBar();
		initSideBar();
		getFristPanel();
		initConnection(DEFALT_HOST, DEFAULT_PORT );
		setVisible( true ); // display frame
	}
	
	private void initConnection(String host, int port){
		try {
			client = new ClientModel(host, port, this);
			client.openConnection();
		} catch (IOException e) {
			LogInPanel login = (LogInPanel) panel;
			login.lblNewLabel.setText("Server not found");
			e.printStackTrace();
		}
	}
	
	private void initTopBar(){
		topBar = new TopBar();
		contentPane.add(topBar, BorderLayout.PAGE_START);
	}
	
	private void initSideBar(){
		sideBar = new SideBar();
		contentPane.add(sideBar, BorderLayout.LINE_START);
	}
	
	private void getFristPanel(){
		LogInPanel login = new LogInPanel();
		/*login.btnSubmit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
			}
		});*/
		panel = login;
		contentPane.add(panel, BorderLayout.CENTER);
	}
}
